﻿using GameHubService;
using GameHubService.Dtos;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace GameHubClient.ViewModel;

public class MainViewModel : INotifyPropertyChanged {
    public event PropertyChangedEventHandler? PropertyChanged;

    protected void OnPropertyChanged([CallerMemberName] string name = null) {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
    }

    public ObservableCollection<GameItemDto> ListItems { get; set; }

    protected MainWindow mainWindow;

    /// <summary>
    /// 分类菜单点击命令
    /// </summary>
    public ICommand MenuClick { get; }
    /// <summary>
    /// 游戏项点击事件
    /// </summary>
    public ICommand GameItemClick { get; }


    public MainViewModel(MainWindow _mainWindow) {
        mainWindow = _mainWindow;
        MenuClick = new RelayCommand(HandleMenuClick);
        GameItemClick = new RelayCommand(HandleGameItemClick);
        ListItems = new ObservableCollection<GameItemDto> { };
    }

    #region 1.0 游戏项点击事件
    protected void HandleGameItemClick(Object? parameter) {
        // 这里是整个游戏对象 

        if (parameter is GameItemDto obj) {

            MessageBox.Show(obj.Name);
        }
    }
    #endregion


    #region 2.0 分类菜单点击处理
    protected void HandleMenuClick(object? parameter) {
        // string msg = parameter?.ToString();

        if (parameter is string menuName) {
            switch (menuName) {
                case "Home":
                    // 处理 Home 菜单点击
                    break;
                case "Library":
                    // 处理 Library 菜单点击
                    break;
                case "Settings":
                    // 处理 Settings 菜单点击
                    break;
                default:
                    // 处理其他菜单点击
                    break;
            }
        }

        for (int i = 1; i <= 10; i++) {
            GameItemDto dto = new GameItemDto {
                Id = i.ToString(),
                Name = $"游戏{(i + 1).ToString("D3")}", Icon = "/Assets/icons/tools.png"
            };
            ListItems.Add(dto);
        }

        GameEntity entity = new GameEntity { Id = "1", Name = "测试游戏", Code = "test_game", Status = 100 };
        entity.Id = SnowFlakeSingle.Instance.NextId().ToString();
        new GameRepository().Insert(entity);

    } 
    #endregion



}
